package com.sx.zongzhi.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.activity.ImagePlayActivity;
import com.sx.zongzhi.bean.OverseasBean;
import com.sx.zongzhi.net.ServiceFactory;
import com.sx.zongzhi.utils.BaseUtil;

import java.io.File;
import java.util.List;

/**
 * Created by XZY on 2017/11/23.
 * 境外人员
 */

public class OverseasAdapter extends BaseQuickAdapter<OverseasBean.RowsBean,BaseViewHolder> {

    private Context context;

    public OverseasAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<OverseasBean.RowsBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, OverseasBean.RowsBean item) {

        helper.setText(R.id.tv_NameId,item.getNameFont());
        helper.setText(R.id.tv_Country,item.getNationality().getDisplayName());
        helper.setText(R.id.tv_Sex,item.getGender().getDisplayName());
        helper.setText(R.id.tv_Age,item.getAge()+"岁");
        helper.setText(R.id.tv_Address,item.getCurrentAddress());
        ImageView imageView=helper.getView(R.id.imv_Head);
        if (!BaseUtil.isEmpty(item.getImgUrl())) {
            final String path = ServiceFactory.NEW_API_BASE_URL + File.separator + item.getImgUrl();
            RequestOptions options = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.mipmap.head_default)
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
            Glide.with(context)
                    .load(path)
                    .apply(options)
                    .into(imageView);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context, ImagePlayActivity.class)
                    .putExtra("path",path));
                }
            });
        }
    }
}
